//
//  Extension.swift
//  SinaWeibo
//
//  Created by wszyxc on 16/7/19.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
  
    convenience init(imageName:String?,title:String?,target: AnyObject?, action: Selector) {
        
        //调用父类的初始化
        self.init()
        
        let buttonItem:UIButton = UIButton()
        
        if let img = imageName{
            
            buttonItem.setImage(UIImage(named: img), forState: .Normal)
        }
        
        if let tit = title{
            
            buttonItem.setTitle(tit, forState: .Normal)
            buttonItem.setTitleColor(UIColor.orangeColor(), forState: .Normal)
            buttonItem.titleLabel?.font = UIFont.systemFontOfSize(15)
        }
        
        buttonItem.setTitleColor(UIColor.grayColor(), forState: .Disabled)
        
        buttonItem.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        //下面这一句很重要,否则生成的buttonbItem将没有frame
        buttonItem.sizeToFit()
        
        self.customView = buttonItem
        
    }
  
    
}


